/**
 * This class will be used to draw the graphical snapshot report for the network manager.
 * This class extends the JPanel class, as each instance will be a panel to place in our frame.
 * 
 * @author Gil Levinson
 * @author Boris Fradlis
 * @author Yogev Levi
 * @author Hila Porat
 *   
 */
package vcpClasses;

import javax.swing.JPanel;

import system.SystemTypes;

import java.awt.*;
import java.util.Vector;

// Start of GraphicReport ****************************************************************

public class GraphicReport extends JPanel {
	
	SystemTypes sysType;

	/**
	 * constructor of an instance for this class
	 * @param myType - the object containing the data for the report
	 */
	
	public GraphicReport(SystemTypes myType)
	{
		this.sysType = myType;
	}
	
	/**
	 * the method will initialize the JPanel and will draw the report on it.
	 */
	
	public void paintComponent(Graphics g)
	{
		super.paintComponents(g);
		this.setBackground(Color.WHITE);
		int i,j,k,x=10,y=50, ySave=0, index =0;
		Vector<ParkingLocation> vec = (Vector<ParkingLocation>) sysType.getObj();
		ParkingLocation location = new ParkingLocation();
		location = vec.lastElement();
		int spaces = location.getParkingSpaceNumber();
		int lot = location.getParkingLotNumber();
		g.setColor(Color.black);
		g.drawString("Graphic report for lot no. : " + lot , x, 10);
		
		for (i=0; i<3; i++)
		{
			g.setColor(Color.DARK_GRAY);
			g.drawString("Floor no. : " + (i+1) , x, 30);
			for (j=0; j<3; j++)
			{
				y+=20;
				g.setColor(Color.MAGENTA);
				g.drawString("Row no. : " + (j+1) , x, 40);
				for (k=0; k< spaces;k++)
				{
					location = vec.get(index);
					switch (location.getParkingSpaceStatus())
					{
						case "FREE":
							g.setColor(Color.GREEN);
							break;
						case "SAVED":
							g.setColor(Color.MAGENTA);
							break;
						case "OCCUPIED":
							g.setColor(Color.BLUE);
							break;
						case "MAINTENANCE":
							g.setColor(Color.RED);
							break;
						case "DAMAGED":
							g.setColor(Color.ORANGE);
							break;
					}
					g.fillRect(x, y, 5, 5);
					y+=10;
					index++;
				}
				ySave = y;
				y=50;
				x+=80;
			}
			x+=50;
		}
		ySave+=20;
		g.setColor(Color.black);
		g.drawString("Legend: " , 10, ySave);
		g.setColor(Color.GREEN);
		g.fillRect(10,ySave+20, 5, 5);
		g.drawString("FREE"  , 20, ySave+30);
		g.setColor(Color.MAGENTA);
		g.fillRect(10, ySave+40, 5, 5);
		g.drawString("SAVED" , 20, ySave+50);
		g.setColor(Color.BLUE);
		g.fillRect(10, ySave+60, 5, 5);
		g.drawString("OCCUPIED" , 20, ySave+70);
		g.setColor(Color.RED);
		g.fillRect(10, ySave+80, 5, 5);
		g.drawString("MAINTENANCE" , 20, ySave+90);
		g.setColor(Color.ORANGE);
		g.fillRect(10, ySave+100, 5, 5);
		g.drawString("DAMAGED", 20,ySave+110);
	}
} // End of GraphicReport
